<%@page import="java.util.Set"%>
<%@page import="com.swim.entity.RegisteredUser"%>
<%@page import="com.swim.entity.SkillRequest"%>
<%@page import="com.swim.entity.CollaborationRequest"%>
<%@page import="com.swim.entity.FriendshipRequest"%>
<%@page import="com.swim.entity.Collaboration"%>
<%@page import="com.swim.entity.Skill"%>
<%@page import="java.util.List"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />



<title>SWIM - Profile</title>
<link href='http://fonts.googleapis.com/css?family=Arvo'
	rel='stylesheet' type='text/css' />
<link href="css/style.css" rel="stylesheet" type="text/css"
	media="screen" />
<script type='text/javascript'>
	
		function makeRequest(from,to,requestURL,direct){
			var form = document.createElement("form");
		    form.setAttribute("method", "post");
		    form.setAttribute("action", requestURL);

		    var hiddenField = document.createElement("input");
		    hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", "from");
            hiddenField.setAttribute("value", from);
		    form.appendChild(hiddenField);

		    hiddenField = document.createElement("input");
		    hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", "to");
            hiddenField.setAttribute("value", to);
		    form.appendChild(hiddenField);
		    
		    hiddenField = document.createElement("input");
		    hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", "direct");
            hiddenField.setAttribute("value", direct);
		    form.appendChild(hiddenField);
		    
		    document.body.appendChild(form);
		    form.submit();	
		}
</script>
</head>
<body>

<% RegisteredUser usr = (RegisteredUser) request.getAttribute("user");%>
<%
	Object admin = request.getSession().getAttribute("admin");
	%>
	<div id="menu-wrapper">
		<div id="menu">
			<ul>
				
				<li><a href="index.jsp">Homepage</a></li>
				<li><a href="collaboration.jsp">Collaborations</a></li>
				<li><a href="friends.jsp">Friends</a></li>
				
				<li><a href="edit.jsp">Edit Profile</a></li>
				<li><a href="logout.jsp">Logout</a></li>
				
				<%if (admin == null || !(Boolean) admin) {
				%>	
				<li><a href="newskillreq.jsp">Request Skill</a></li>
				<%} else { %>
					<li><a href="newskill.jsp">Create Skill</a></li>
				<%} %>
				
			</ul>
		</div>
		<!-- end #menu -->
	</div>

	<div id="wrapper">
		<div id="header-wrapper">
			<div id="header">
				<div id="logo">
					<h1>
						<a href="#">SWIM</a>
					</h1>
					<p>"A social network for friends needing or offering help"</p>
				</div>
			</div>
		</div>
		<!-- end #header -->
		<div id="page">
			<div id="page-bgtop">
				<div id="page-bgbtm">
					<div id="content">
					
						<div class="post">
								<h2 class="title"><%= usr.getName()+" "+usr.getSurname() %></h2><%
									if(request.getAttribute("canReqFriendship") != null && ((Boolean)request.getAttribute("canReqFriendship"))) { %>
										is not your friend yet. <a href="javascript:makeRequest('<%= session.getAttribute("authenticated-email")+"','"+usr.getEmail()+"', 'friendreq.jsp','"+request.getAttribute("direct")+"'" %>);">Add to friends</a>
									<% } %>
									
								<h1 class="title" style="font-size: 17px;">Offered Collaborations</h2>
								<div class="entry">
								<% List<Collaboration> list = (List<Collaboration>) request.getAttribute("collaborationsOffered");
									for(Collaboration c: list) {
										%>
											
											<ul>
												<li><b>Collaboration date:</b> <%= c.getDate() %></li>
												<li><b>Helping:</b> <%= "<a href=\"profile.jsp?email="+c.getEmailTo().getEmail()+"\">"+c.getEmailTo().getName() %></a></li>
												<li><b>Skill involved:</b> <%= c.getIdSkill().getName() %></li>
												<% if(c.getIdFeedback() != null) { %>
													<li><b>Received Feedback:</b> "<%= c.getIdFeedback().getDescription() %>"</li>
											<% }
											out.println("</ul>");
									} %>
								</div>
							</div>
							
						<div class="post">
							<div class="entry">
								<h1 class="title" style="font-size: 17px;">Friends</h1>
								<ol>
								
								<% Iterable<RegisteredUser> friends = (Iterable<RegisteredUser>) request.getAttribute("friends");
								for(RegisteredUser u: friends) {
									%><li><a href="profile.jsp?email=<%= u.getEmail() %>"><%= u.getName() %></a></li><%					
								} %>
								
								</ol>
							</div>
						</div>						
						<div style="clear: both;">&nbsp;</div>
					</div>
					<!-- end #content -->
					<div id="sidebar">
						<ul>
							<li>
								<h2>Request collaboration</h2>
								<div style="margin-left: 7%;">
									<form method="post" action="collabreq.jsp">
									<div>
										<div>
											<select name="skill" style="margin-right: 10px;">
									
									
												<%
													List<Skill> skills = (List<Skill>) request.getAttribute("userSkills");
													for (Skill s : skills) {
												%>
														<option><%=s.getName()%></option>
												<%
													}
												%>
											</select>
											<input type="submit" value="Request" style="margin-left: 10px;"/>
										</div>
										<input type="hidden" name="to" value="<%= usr.getEmail() %>"/>
										<input type="hidden" name="from" value="<%= session.getAttribute("authenticated-email") %>"/>
										
									</div>
								</form>
								</div>
							</li>
						</ul>
					</div>
					<!-- end #sidebar -->
					<div style="clear: both;">&nbsp;</div>
				</div>
			</div>
		</div>
		<!-- end #page -->
	</div>
	<div id="footer">
		<p></p>
	</div>
	<!-- end #footer -->
</body>
</html>